package com.itcast.rabbitmq.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionUtil {

    public static Connection getConnection() throws Exception {
        //创建连接工厂(设置RabbitMQ的连接参数)
        ConnectionFactory connectionFactory = new ConnectionFactory();
        //主机;默认为localhost
        connectionFactory.setHost("localhost");
        //端口号;默认了5672
        connectionFactory.setPort(5672);
        //虚拟主机;默认为/
        connectionFactory.setVirtualHost("/test");
        //用户名;默认为guest
        connectionFactory.setUsername("sonl_lzj_");
        //密码;默认为guest
        connectionFactory.setPassword("aiwuxian123");
        //创建连接
        return connectionFactory.newConnection();
    }
}
